package com.example.monitoringsystem.controller;
import com.example.monitoringsystem.bean.*;
import com.example.monitoringsystem.currentUser.StaticUser;
import com.example.monitoringsystem.service.NewUserService;
import com.example.monitoringsystem.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.testng.IMethodInstance;

import java.util.HashMap;
import java.util.Map;
@RestController
public class NewUserController {
    @Autowired
    NewUserService userService;

    @RequestMapping("/patient")
    @ResponseBody
    public Object getUser() {
        User user = (User) userService.findUser ();
        return user;
    }

    @RequestMapping("/doctor")
    @ResponseBody
    public Object getDoctor() {
        User user = (User) userService.findUser ();
        return user;
    }

    @RequestMapping("/administrator")
    @ResponseBody
    public Object getAdministrator() {
        User user = (User) userService.findUser ();
        return user;
    }

    @RequestMapping("/patient/mydoctor")
    @ResponseBody
    public Object getPatientDoctor() {
        Patient patient = (Patient) userService.findPatientById ( StaticUser.getCurrentUser ().getId () );
        Doctor doctor = (Doctor) userService.findDoctorByPatient ( patient.getDoctor () );
        return doctor;
    }

    @PostMapping(value = "/user/edit")
    @ResponseBody
    public void prescribe(User user) {
        userService.updateUser ( user );
//        Subject subject = SecurityUtils.getSubject ();
//        User currentUser = (User) subject.getPrincipal ();
//        userService.updateName ( user.getUsername (),currentUser.getId () );
//        userService.updatePassword ( user.getPassword () ,currentUser.getId ());
//        userService.updatePassword ( user.getPassword (),currentUser.getId () );
//        userService.updateEmail ( user.getEmail () ,currentUser.getId ());
        System.out.println (user.getId ());

    }
//        prescribeService.prescribe(prescription, patientId, notice);
////        return "添加成功";
//    @RequestMapping(value = "/user/{userName}", method = RequestMethod.GET)
//    @ResponseBody
//    public String changeName(@RequestParam(value = "usrName") String usrName) {
//        if( userService.updateName ( usrName ))
//        {
//            return "更新成功";
//        }
//        else
//        {
//            return  null;
//        }
//    }
//    @RequestMapping(value = "/user/{password}", method = RequestMethod.POST)
//    @ResponseBody
//    public String changePassword(@RequestParam(value = "password") String password) {
//        if( userService.updatePassword ( password ))
//        {
//            return "更新成功";
//        }
//        else
//        {
//            return  null;
//        }
//    }
//    @RequestMapping(value = "/user/{age}", method = RequestMethod.POST)
//    @ResponseBody
//    public String changePassword(@RequestParam(value = "age") int age) {
//        if (userService.updateAge ( age )) {
//            return "更新成功";
//        } else {
//            return null;
//        }
//    }
//    @RequestMapping(value =" /user/{email}", method = RequestMethod.POST)
//    @ResponseBody
//    public String changeEmail(@RequestParam(value = "email") String email) {
//        if( userService.updateEmail ( email))
//        {
//            return "更新成功";
//        }
//        else
//        {
//            return  null;
//        }
//    }

}
